package com.example.moduletwo.binder;

import android.os.Handler;
import android.text.TextUtils;

import com.example.moduletwo.bean.TwoMVPBean;
import com.example.moduletwo.delegate.ModuleTwoMVPActivityDelegate;
import com.example.mvp.binder.BaseDataBinder;

/**
 * 数据视图绑定（数据驱动视图有延迟刷新）
 * Created by sun.li on 2018/6/5.
 *
 * @author sun.li
 */

public class TwoMVPBinder implements BaseDataBinder<ModuleTwoMVPActivityDelegate,TwoMVPBean>{

    @Override
    public void viewBindModel(ModuleTwoMVPActivityDelegate viewDelegate, TwoMVPBean data) {
        if(null == data || null == viewDelegate){
            return;
        }
        str1BindView(viewDelegate,data.getStr1());

        if(!TextUtils.isEmpty(data.getStr2())){
            viewDelegate.setText2(data.getStr2());
        }

        new TwoMVPBinderOne().viewBindModel(viewDelegate,data.getTwoMVPBeanOne());
    }

    @Override
    public Class<TwoMVPBean> getDataClass() {
        return TwoMVPBean.class;
    }

    /** 数据对象1业务处理*/
    private void str1BindView(final ModuleTwoMVPActivityDelegate viewDelegate, final String str1) {
        if(!TextUtils.isEmpty(str1)){
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    viewDelegate.setText1(str1);
                }
            },3000);
        }
    }


}
